﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace ActionSystem.Core.AnimationLogic
{
    public class AnimatorAnimationAbility : BaseAnimationAbility,IStateMachineChange
    {
        Animator animator; 
        public AnimatorAnimationAbility(BaseStateMachine baseStateMachine,Animator animator) : base(baseStateMachine)
        {
            this.animator = animator;
            animator.enabled = false;
            baseStateMachine.AddStateChanegCallback(this);
        }
        public Animator GetAnimator() { return animator; }
        public override void AnimationEvaluate()
        {
            animator.Update(StateMachine.LogicDeltaTime);
        }

        public void OnDestroy()
        {
            
        }

        public void OnStateChange(BaseState currenState, BaseState nextState, StateBlendData blendData)
        {
            var name = nextState as IAnimationName;
            if (name != null)
            {
                animator.CrossFadeInFixedTime(name.GetAnimationName(), blendData.transTotalFrame * ActionSystemManager.Instance.GlobalConfig.FrameTime);
            }
        }
    }
}
